#ifndef _INFLASH_H_
#define _INFLASH_H_

#include "main.h"

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/

#define FLASH_BASE_ADDR      (uint32_t)(FLASH_BASE)
#define FLASH_END_ADDR       (uint32_t)(0x08100000)

/**
 **   Boot程序占用前5个sector（FLASH_SECTOR_0 -- 4），4*16K+64K；起始地址0x08000000
 **   APP占用4个sector，FLASH_SECTOR_5 -- 8；起始地址0x08020000 前两个是运行sector，后两个是备份sector
 **   要注意生成的固件的大小，不要超过两个sector
 **   FLASH_SECTOR_9用来存放升级成功标志；起始地址：0x080A0000
 **   FLASH_SECTOR_10 -- 11是APP里用做模拟eeprom；起始地址：0x080C0000
 **/
#define APP_SECTOR_SIZE         0x20000
#define APP_SECTOR_NUM          2
#define APP_LENGTH              (APP_SECTOR_SIZE*APP_SECTOR_NUM)
#define APP_ADDR                0x08020000
#define APP_ADDR_END            (APP_ADDR+APP_LENGTH)
#define APP_BACKUP_ADDR         APP_ADDR_END
#define APP_BACKUP_ADDR_END     (APP_BACKUP_ADDR+APP_LENGTH)
#define APP_CRC32_ADDR          0x080A0000
#define FLASH_EEP_ADDR          (uint32_t)(FLASH_BASE + 0xC0000)
/* Exported functions ------------------------------------------------------- */

#define FLASH_WAITETIME     50000          //FLASH等待超时时间


uint32_t    InFLASH_Write(uint32_t FlashAddress, uint32_t *DataAddr ,uint32_t DataLength);
void        InFLASH_Read(uint32_t FlashAddress, uint32_t* pData, uint32_t DataLength);
void        BD_INFLASH_Init(void);
HAL_StatusTypeDef InFlash_Erase(uint32_t startAddr,size_t len);

#endif






